package com.swak.frame.dto.response;

import java.util.List;

import com.swak.frame.dto.base.RestApiCode;
import com.swak.frame.dto.base.SysRestCode;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * Response with batch record to return, usually use in page query or
 * conditional query {@link RpcResponse}
 * 
 * @ClassName: MultiResponse.java
 * @author: colley.ma
 * @date: 2022/01/25
 */
@ApiModel(value = "MultiResponse结果")
public class MultiResponse<T> extends RpcResponse<List<T>> {
	private static final long serialVersionUID = -2540075203092967399L;

	@ApiModelProperty(value = "总数")
	private Integer total;

	public MultiResponse() {
		super(SysRestCode.SUCC);
	}

	public MultiResponse(String retCode, String retMessage) {
		super(retCode, retMessage);
	}

	public MultiResponse(RestApiCode restCode) {
		this(restCode.getRetCode(), restCode.getRetMessage());
	}

	@Override
	public MultiResponse<T> ofResult(List<T> data) {
		super.ofResult(data);
		this.total = 0;
		return this;
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public static class Builder<T> extends RpcResponse.Builder<List<T>> {
		private int total;

		public Builder() {
			super();
		}

		public Builder<T> total(Integer total) {
			this.total = total;
			return this;
		}

		@Override
		public MultiResponse<T> build() {
			return new MultiResponse<T>(this);
		}

		@Override
		public Builder<T> retCode(String retCode) {
			super.retCode(retCode);
			return this;
		}

		@Override
		public Builder<T> of(RestApiCode restCode) {
			super.of(restCode);
			return this;
		}

		@Override
		public Builder<T> retMessage(String retMessage) {
			super.retMessage(retMessage);
			return this;
		}

		@Override
		public Builder<T> of(String retCode, String retMessage) {
			super.of(retCode, retMessage);
			return this;
		}

		@Override
		public Builder<T> result(List<T> result) {
			super.result(result);
			return this;
		}

	}

	protected MultiResponse(Builder<T> builder) {
		super(builder);
		this.total = builder.total;
	}
}
